package mutsumimod.cards.custom;

import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import mutsumimod.cards.BaseCard;
import mutsumimod.character.Mutsumi;
import mutsumimod.powers.TwoPeopleOneBodyPower;
import mutsumimod.util.CardStats;
import mutsumimod.util.CardUtils;

import java.util.*;
import java.util.stream.Collectors;

public class TwoPeopleOneBody extends BaseCard {
    public static final String ID = makeID(TwoPeopleOneBody.class.getSimpleName());
    public static final CardStats info = new CardStats(
            Mutsumi.Meta.CARD_COLOR,
            CardType.POWER,
            CardRarity.UNCOMMON,
            CardTarget.SELF,
            1
    );

    public TwoPeopleOneBody() {
        super(ID, info);
        setAttr(0,0,1);
        setAttrUpg(0,0,0);
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        applyPowerSelf(new TwoPeopleOneBodyPower(p));
    }

    @Override
    public AbstractCard makeCopy() {
        return new TwoPeopleOneBody();
    }

    public static ArrayList<AbstractCard> getTenSubXCard(int count, int standTag,AbstractCard... ignores) {
        ArrayList<AbstractCard> result = new ArrayList<>();
        HashMap<String, BaseCard> targetMap = CardUtils.modCards;

        if (targetMap == null || targetMap.isEmpty()) return result;

        ArrayList<BaseCard> candidates = new ArrayList<>(targetMap.values());
        Set<String> excludeIds = Arrays.stream(ignores)
                .map(c -> c.cardID)
                .collect(Collectors.toSet());

        Collections.shuffle(candidates, new Random(AbstractDungeon.miscRng.randomLong()));

        for (BaseCard card : candidates) {
            if (result.size() >= count) break;
            if (!excludeIds.contains(card.cardID)&&card.standTag==standTag) {
                result.add(card);
                excludeIds.add(card.cardID);
            }
        }
        return result;
    }

    @Override
    public void upgrade() {
        if(!this.upgraded) {
            this.upgradeName();
            upgradeBaseCost(baseCost-1);
        }
    }


}
